/**
 * 
 */
package net.jbaez.code;

import java.lang.reflect.Modifier;

/*
 * Copyright 2008 DynamiCode 
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *
 * http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an 
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 * either express or implied. See the License for the specific 
 * language governing permissions and limitations under the License. 
 */
/**
 * Enumeracion con los tipos
 * de visibilidad
 */
public enum JVisibility {
	
	PUBLIC(Modifier.PUBLIC, Modifier.toString(Modifier.PUBLIC)),
	PROTECTED(Modifier.PROTECTED, Modifier.toString(Modifier.PROTECTED)),
	PACKAGE(-12345, ""),
	PRIVATE(Modifier.PRIVATE, Modifier.toString(Modifier.PRIVATE));
	
	
	//Valor de la visibilidad en java
	private int intValue;
	//Representacion en texto
	private String code;
	
	JVisibility(int intValue, String code){
		this.intValue = intValue;
		this.code = code;
	}
	
	/**
	 * Retorna la visibilidad que representa
	 * el valor pasado como parametro
	 * @param intValue Valor a verificar
	 * @return Visibilidad a la que pertenece
	 */
	public static JVisibility getVisibility(int intValue){
	    if(Modifier.isPublic(intValue)) return PUBLIC;
	    if(Modifier.isPrivate(intValue)) return PRIVATE;
	    if(Modifier.isProtected(intValue)) return PROTECTED;
	    if(PACKAGE.intValue == intValue) return PACKAGE;
	    return null;
	}
	
	/**
	 * @return the intValue
	 */
	public int getIntValue() {
		return intValue;
	}
	
	public String toString(){
		return code;
	}
}
